package com.bupt.controller;

import com.bupt.bean.DeviceType;
import com.bupt.config.DeviceTypeResult;
import com.bupt.config.QueryResponseResult;
import com.bupt.config.Result;
import com.bupt.service.DeviceService;
import com.bupt.service.PageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value="设备类型接口",description="设备类型的增删改查")
@RestController
public class DeviceTypeController {

    @Autowired
    private PageService pageService;

    @Autowired
    private DeviceService deviceService;


    @ApiOperation("分页查询设备类型页面列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "页码", required = true, paramType = "path", dataType = "int"), @ApiImplicitParam(name = "size", value = "每页记录数", required = true, paramType = "path", dataType = "int")})
    @GetMapping("/deviceTypePage/{page}/{size}")
    public QueryResponseResult deviceTypePage(@PathVariable("page") int page, @PathVariable("size") int size) {
        return pageService.findDeviceTypeList(page, size);
    }

    @ApiOperation("添加设备类型")
    @PutMapping("/deviceType/add")
    public DeviceTypeResult addDeviceType(@RequestBody DeviceType deviceType) {
        return deviceService.addDeviceType(deviceType);
    }


    @ApiOperation("通过ID修改设备类型")
    @PostMapping("/deviceType/edit/{deviceTypeId}")
    public DeviceTypeResult editDeviceType(@PathVariable("deviceTypeId") Integer deviceTypeId,@RequestBody DeviceType deviceType) {
        return deviceService.editDeviceType(deviceTypeId,deviceType);
    }

    @ApiOperation("通过ID删除设备类型")
    @DeleteMapping("/deviceType/deleteById/{deviceTypeId}")
    public Result deleteDeviceTypeById(@PathVariable("deviceTypeId") Integer deviceTypeId) {
        return deviceService.deleteDeviceTypeById(deviceTypeId);
    }
}
